﻿using System.Collections.Generic;
using System.Linq;
using AB.ServiceDirectory.Commons.DataFilters;
using AB.ServiceDirectory.Dao;
using AB.ServiceDirectory.Entities;

namespace AB.ServiceDirectory.BO
{
    public sealed class ServiceBO
    {
        private static readonly ServiceDao Dao = new ServiceDao();

        private ServiceBO()
        {
        }

        /// <summary>
        /// Gets the list.
        /// </summary>
        /// <param name="filter">The filter.</param>
        /// <param name="sortType">Type of the sort.</param>
        /// <param name="startRowIndex">Start index of the row.</param>
        /// <param name="maxRows">The max rows.</param>
        /// <returns></returns>
        public static IQueryable<Service> GetList(ServiceFilter filter, string sortType, int startRowIndex, int maxRows)
        {
            return Dao.GetList(filter, sortType, startRowIndex, maxRows);
        }

        /// <summary>
        /// Gets the list count.
        /// </summary>
        /// <param name="filter">The filter.</param>
        /// <returns></returns>
        public static int GetListCount(ServiceFilter filter)
        {
            return Dao.GetListCount(filter);
        }

        /// <summary>
        /// Gets the service by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public static Service GetServiceById(int id)
        {
            return Dao.GetServiceById(id);
        }

        /// <summary>
        /// Sets the service status.
        /// </summary>
        /// <param name="serviceId">The service id.</param>
        /// <param name="status">if set to <c>true</c> [status].</param>
        public static bool SetServiceStatus(int serviceId, bool status)
        {
            return Dao.SetServiceStatus(serviceId, status);
        }

        /// <summary>
        /// Gets the service reference data by category id.
        /// </summary>
        /// <param name="categoryId">The category id.</param>
        /// <returns></returns>
        public static IQueryable<ServiceReferenceData> GetServiceReferenceDataByCategoryId(int categoryId)
        {
            return Dao.GetServiceReferenceDataByCategoryId(categoryId);
        }

        /// <summary>
        /// Gets the service reference by id.
        /// </summary>
        /// <param name="serviceId">The service id.</param>
        /// <returns></returns>
        public static ServiceReference GetServiceReferenceById(int serviceId)
        {
            return Dao.GetServiceReferenceById(serviceId);
        }

        /// <summary>
        /// Gets the intervention for service.
        /// </summary>
        /// <param name="serviceId">The service id.</param>
        /// <returns></returns>
        public static IQueryable<Intervention> GetInterventionForService(int serviceId)
        {
            return Dao.GetInterventionForService(serviceId);
        }

        /// <summary>
        /// Gets the other active service.
        /// </summary>
        /// <param name="serviceId">The service id.</param>
        /// <returns></returns>
        public static IQueryable<Service> GetOtherActiveService(int serviceId)
        {
            return Dao.GetOtherActiveService(serviceId);
        }

        /// <summary>
        /// Adds the service.
        /// </summary>
        /// <param name="service">The service.</param>
        /// <returns></returns>
        public static bool AddService(Service service)
        {
            return Dao.AddService(service);
        }

        /// <summary>
        /// Edits the service.
        /// </summary>
        /// <param name="service">The service.</param>
        /// <returns></returns>
        public static bool EditService(Service service)
        {
            return Dao.EditService(service);
        }

        /// <summary>
        /// Edits the intervention list.
        /// </summary>
        /// <param name="interventions">The interventions.</param>
        /// <returns></returns>
        public static bool EditInterventionList(ICollection<Intervention> interventions)
        {
            return Dao.EditInterventionList(interventions);
        }

        /// <summary>
        /// Determines whether [is name exists] [the specified service name].
        /// </summary>
        /// <param name="serviceName">Name of the service.</param>
        /// <returns>
        ///   <c>true</c> if [is name exists] [the specified service name]; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsNameExists(string serviceName)
        {
            return Dao.IsNameExists(serviceName);
        }

        /// <summary>
        /// Adds the internal service.
        /// </summary>
        /// <param name="list">The list.</param>
        /// <returns></returns>
        public static bool AddInternalService(IEnumerable<InternalService> list)
        {
            return Dao.AddInternalService(list);
        }

        /// <summary>
        /// Edits the organization program.
        /// </summary>
        /// <param name="serviceId">The organization id.</param>
        /// <param name="list">The list.</param>
        /// <returns></returns>
        public static bool EditInternalService(int serviceId, ICollection<InternalService> list)
        {
            return Dao.EditInternalService(serviceId, list);
        }


        /// <summary>
        /// Gets the internal service.
        /// </summary>
        /// <param name="serviceId">The service id.</param>
        /// <returns></returns>
        public static IQueryable<InternalService> GetInternalService(int serviceId)
        {
            return Dao.GetInternalService(serviceId);
        }
    }
}